package com.oot2d.world;

import com.oot2d.entity.Entity;
import com.oot2d.entity.NPC;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Music;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Vector2f;

import java.util.ArrayList;

public class World {
    public Map[] maps;
    private float spawnx;
    private float spawny;
    private Music music;

    private float transition = 0.0f;
    private Image title;

    public World(String map1, String map2, Object spawn)
    {
        maps = new Map[2];
        maps[0] = new Map(map1);
        maps[1] = (!map2.equals("none")) ? new Map(map2) : null;

        ArrayList<Integer> s = (ArrayList<Integer>)spawn;
        spawnx = (float)s.get(0);
        spawny = (float)s.get(1);

        try {
            music = new Music("res/music/kokiri.ogg");
        } catch (SlickException e) {
            System.err.println(e.getMessage());
        }
    }

    public void load()
    {
        maps[0].load();
        if (maps[1] != null)
            maps[1].load();

        //if (music != null)
            //music.play(1.0f, 0.3f);
    }

    public Tile tileAt(float x, float y, int z, int i)
    {
        return maps[i].tileAt(x, y, z);
    }

    public Vector2f getSpawn()
    {
        return new Vector2f(spawnx, spawny);
    }

    public int getWidth()
    {
        return maps[0].getWidth() * 16;
    }

    public int getHeight()
    {
        return maps[0].getHeight() * 16;
    }

    public Music getMusic()
    {
        return music;
    }

    public boolean hasTop()
    {
        return (maps[1] != null);
    }

    public ArrayList<Entity> getEntities(int i)
    {
        return maps[i].getEntities();
    }

    public ArrayList<NPC> getNPCs(int i)
    {
        return maps[i].getNPCs();
    }

    public void update(int d)
    {
        maps[0].update(d);
        if (hasTop())
            maps[1].update(d);
    }

    public void render(Graphics g, int i, float wx, float wy)
    {
        maps[i].draw(g, wx, wy);
    }

    public void renderOverlay(int i, float wx, float wy)
    {
        maps[i].drawOverlay(wx, wy);
    }
}
